﻿using QuotingTool.DataModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuotingTool.Utility;
using System.Globalization;

namespace QuotingTool.Domain.Models
{
    public class MaintenanceLinesData
    {
        public static DataTable GetMaintenanceLinesAllColumns(DBQuote Quote)
        {
            List<DBLineItem> Lines = Quote.Lines;
            CultureInfo ci = new CultureInfo("en-US");
            List<MaintenanceLines> maintenanceLines = new List<MaintenanceLines>();

            foreach (DBLineItem line in Lines)
            {
                MaintenanceLines maintenanceLine = new MaintenanceLines();

                maintenanceLine.MaintenanceLineName = line.MAINTENANCE_ITEM;
                maintenanceLine.Description = line.MAINTENANCE_ITEM_DESCRIPTION;

                if (!string.IsNullOrEmpty(line.START_DATE))
                {
                    maintenanceLine.StartDate = DateTime.Parse(line.START_DATE).ToString("dd MMM yyyy", ci);
                }
                if (!string.IsNullOrEmpty(line.END_DATE))
                {
                    maintenanceLine.EndDate = DateTime.Parse(line.END_DATE).ToString("dd MMM yyyy", ci);
                }
                // Duration
                maintenanceLine.RenewalPeriod = line.DURATION;
                maintenanceLine.AnnualMaintenanceCostIncludingCOL = line.TOTAL_AMOUNT;
             
                maintenanceLines.Add(maintenanceLine);
            }
         
            return Common.ToDataTable(maintenanceLines);
        }
    }
}
